from django.db import models
from DjangoUeditor.models import UEditorField


# Create your models here.
class CityInfo(models.Model):
    name = models.CharField('城市名称', max_length=20)
    add_time = models.DateTimeField('添加时间', auto_now_add=True)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '城市信息'
        verbose_name_plural = verbose_name


class OrgInfo(models.Model):
    image = models.ImageField('机构封面', upload_to='org/', max_length=200)
    name = models.CharField('机构名称', max_length=20)
    course_num = models.IntegerField('课程数', default=0)
    study_num = models.IntegerField('学习人数', default=0)
    address = models.CharField('机构地址', max_length=200)
    desc = models.CharField('机构简介', max_length=200)
    detail = UEditorField(verbose_name='机构详情',
                          width=700,
                          height=400,
                          toolbars='full',
                          imagePath='ueditor/images/',
                          filePath='ueditor/files/',
                          upload_settings={'imageMaxSizing': 1024000},
                          default='')
    love_num = models.IntegerField('收藏数', default=0)
    click_num = models.IntegerField('访问量', default=0)
    category = models.CharField('机构类别', choices=(('pxjg', '培训机构'), ('gx', '高校'), ('gr', '个人')), max_length=10)
    add_time = models.DateTimeField('添加时间', auto_now_add=True)

    cityInfo = models.ForeignKey(CityInfo, verbose_name='所在城市', on_delete=models.CASCADE)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '机构信息'
        verbose_name_plural = verbose_name


class TeacherInfo(models.Model):
    image = models.ImageField('讲师头像', upload_to='teacher/', max_length=200)
    name = models.CharField('讲师姓名', max_length=20)
    work_year = models.IntegerField('工作年限', default=3)
    work_position = models.CharField('工作职位', max_length=20)
    work_style = models.CharField('教学特点', max_length=20)
    age = models.IntegerField('讲师年龄', default=30)
    gender = models.CharField('讲师性别', choices=(('boy', '男'), ('girl', '女')), max_length=10, default='boy')
    love_num = models.IntegerField('收藏数', default=0)
    click_num = models.IntegerField('访问量', default=0)
    add_time = models.DateTimeField('添加时间', auto_now_add=True)

    work_company = models.ForeignKey(OrgInfo, verbose_name='所属机构', on_delete=models.CASCADE)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '讲师信息'
        verbose_name_plural = verbose_name
